package com.inspur_video.inspur_video.service;

import com.inspur_video.inspur_video.bean.Member;
import com.inspur_video.inspur_video.dao.MemberDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 *
 * @author 小浩
 * @date 2018-08-14 18:03
 * @package com.inspur_video.inspur_video.service
 * @description
 */
@Service
public class VipService {
    @Autowired
    MemberDao memberDao;
    public boolean isVip(int uid){
        Member member = memberDao.findByUId(uid);
        if (member==null){
            return false;
        }
        try {
            Date endTime=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                    .parse(member.getEndTime());
            return endTime.compareTo(new Date())>0?true:false;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return false;
    }

    public boolean setVip(int uid,String entTime){
        Member member=new Member();
        member.setUId(uid);
        member.setBeginTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        member.setMGrade(1);
        member.setEndTime(entTime);
        return memberDao.save(member)!=null?true:false;
    }
}
